/*
 * @Author: 专送Pro
 * @Date: 2019-08-23 13:17:18
 * @LastEditors  : wuzhen
 * @LastEditTime : 2020-01-08 19:36:29
 * @Description: 配置文件
 */
/* eslint-disable */
import { closeNotice } from "@/request/api";
export default {
  data() {
    return {
      // 搜索参数配置
      searchProps: [
        {
          label: "通知标题",
          type: "text",
          key: "title",
          placeholder: "请输入通知标题"
        },
        {
          label: "创建时间",
          type: "daterange",
          key: "date",
          placeholder: "请选择创建时间"
        }
      ],
      searchButtons: [
        {
          text: "添加通知",
          btnType: "add",
          type: "primary"
        }
      ],
      columns: [
        {
          title: "序号",
          type: "index",
          width: 80,
          indexMethod: row => {
            return row._index + 1 < 10 ? `0${row._index + 1}` : row._index + 1;
          }
        },
        {
          title: "通知标题",
          key: "title",
          width: 160
        },
        {
          title: "通知内容",
          key: "username",
          render(h, params) {
            const row = params.row;
            return h("p", row.content);
          }
        },
        {
          title: "创建时间",
          width: 170,
          render: (h, params) => {
            const row = params.row;
            return h("span", this.$fmtMoment(row.createtime));
          }
        },
        {
          title: "通知对象",
          width: 100,
          render: (h, params) => {
            const row = params.row;
            return h(
              "span",
              row.noticetarget === 1
                ? "新用户"
                : row.noticetarget === 2
                ? "老用户"
                : "全员"
            );
          }
        },
        {
          title: "操作",
          width: 100,
          render: (h, params) => {
            const row = params.row;
            return h(
              "span",
              {
                class: {
                  primary: row.status === 10,
                  disabled: row.status !== 10
                },
                on: {
                  click: async () => {
                    if (row.status !== 10) {
                      return;
                    }
                    try {
                      this.$Modal.warning({
                        title: "友情提示",
                        content: "确定要关闭该通知吗？",
                        closable: true,
                        onOk: async () => {
                          const res = await closeNotice({
                            sysnoticeid: row.sysnoticeid
                          });
                          if (res.code === 200) {
                            this.$Message.success("操作成功");
                            row.status = 20;
                          } else {
                            this.$Message.error("操作失败");
                          }
                        }
                      });
                    } catch (error) {
                      throw error;
                    }
                  }
                }
              },
              "关闭"
            );
          }
        }
      ]
    };
  }
};
